from loguru import logger

from Config import Config
from singleton import singleton
import DobotDllType as dType


@singleton
class DobotApi(object):
    api = None

    def __init__(self):
        self.api = dType.load()
        port = conf_inst = Config().inst().get("dobot", "port")
        state = dType.ConnectDobot(self.api, port, 115200)[0]
        logger.debug(state)
        dType.SetQueuedCmdClear(self.api)
        dType.SetQueuedCmdStartExec(self.api)
        if state != dType.DobotConnect.DobotConnect_NoError:
            logger.critical("DOBOT 连接失败")
            pass
        pass

    def instance(self):
        return self.api

    # todo 报告连接状态
